//
//  StatusModel.swift
//  weibo1990
//
//  Created by 曹晓龙 on 15/10/19.
//  Copyright © 2015年 曹晓龙. All rights reserved.
//

import UIKit

class StatusModel: NSObject {

    // MARK: - 模型属性
    /// 微博ID
    var id:Int = 0
    
    /// 微博信息内容
    var text:String?
    
    /// 微博来源
    var source:String?{
        didSet{
            self.source = source?.href()?.text
        }
    }
    
    /// 微博创建时间
    var created_at:String?
    /// 发布微博用户
    var user:UserModel?
 
    /// 存放微博配图urlString字典的数组
    var pic_urls:[[String: String]]?
    
    /// 转发微博
    var retweeted_status:StatusModel?
    //MARK: - 构造函数
    init(dict:[String : AnyObject]){
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            if let dict = value as? [String : AnyObject] {
                
                user = UserModel(dict: dict)
            }
            
            return
            
        }
        
        if key == "retweeted_status" {
            
            if let dict = value as? [String : AnyObject] {
                
                retweeted_status = StatusModel(dict: dict)
            }
            
            return
        }
            
            
        super.setValue(value, forKey: key)
        
        
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
    
    override var description: String{
        let keys = ["id", "text", "source", "created_at", "user", "pic_urls", "retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}
